﻿using MediatR;
using S.Initial.Domain;
using S.Initial.Infrastructure.Interface;
using S.Initial.Read.API.Controllers.Application.Command.BreedingMothers;
using System.Data;

namespace S.Initial.Read.API.Controllers.Application.CommandHandlers.BreedingMothers
{
    public class ShowBreedingMothersCommandHandler : IRequestHandler<ShowBreedingMothersCommand, (IEnumerable<BreedMaleAndFemaleStart> items, int totalCount, int pageCount)>
    {
        private readonly IBreedingMothersRepository breeding;

        public ShowBreedingMothersCommandHandler(IBreedingMothersRepository breeding)
        {
            this.breeding = breeding;
        }
        /// <summary>
        /// 显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<(IEnumerable<BreedMaleAndFemaleStart> items, int totalCount, int pageCount)> Handle(ShowBreedingMothersCommand request, CancellationToken cancellationToken)
        {
            var result = await breeding.GetAllBreedingmothersBy(request.Type, request.EITag, request.KaiDate, request.JieDate, request.page, request.size);
            var items = result.items;
            var totalCount = result.totalCount;
            var pageCount = result.pageCount;
            return (items, totalCount, pageCount);
        }
    }
}
